<template>
  <z-paging ref="pagingRef" @query="queryList" v-model="list">
    <template #top>
      <MrCustom bg-color="bg-gradual-blue " is-back>
        <template #backText>
          返回
        </template>
      </MrCustom>
      <view class="cu-bar search bg-white">
        <view class="search-form round">
          <text class="cuIcon-search"></text>
          <input type="text" placeholder="搜医生、护士" @confirm="search"/>
        </view>
      </view>
    </template>
    <HospitalPopupSelect @on-change="reload"  v-model:hospital="andParams.hospital" mode="select"></HospitalPopupSelect>
    <view v-for="(item,index) in list" :key="index" @click="toQuery(item)">
      <NurseItem :nurse-item="item"></NurseItem>
    </view>
  </z-paging>
</template>

<script setup lang="ts">

import api from "@/api";
import {ref} from "vue";
import UniCard from "@/uni_modules/uni-card/components/uni-card/uni-card.vue";
import {useUserStore,} from '@/store'
import NurseItem from "@/components/common/item/NurseItem.vue";
import HospitalPopupSelect from "@/components/common/select/HospitalPopupSelect.vue";
import MrCustom from "@/components/common/MrCustom.vue";

const userStore = useUserStore()
const pagingRef = ref()
const list = ref([])
const andParams = ref({
  hospital:'',
})
const orParams = ref({
  name: '',
})
const orderParams = ref({})
const search = (e: any) => {
  let tmp = e.detail.value
  Object.keys(orParams.value).forEach((key: any) => {
    //@ts-ignore
    orParams.value[key] = `%${tmp}%`
  })
  pagingRef.value.reload()
}
const reload=()=>{
  pagingRef.value.reload()
}
const toQuery = (item: any) => {
  uni.navigateTo({
    url: '/pages/common/introduction/nurse?nurseInfo=' + encodeURIComponent(JSON.stringify(item))
  })
}


const queryList = (pageNo: any, pageSize: any) => {
  //组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
  //这里的pageNo和pageSize会自动计算好，直接传给服务器即可
  //模拟请求服务器获取分页数据，请替换成自己的网络请求
  api.nurse.formalList({
    pageNo: pageNo,
    pageSize: pageSize,
    andParams: JSON.stringify(andParams.value),
    orParams: JSON.stringify(orParams.value),
    orderParams: JSON.stringify(orderParams.value),
  }).then(res => {
    if (res && res.data.code === 0) {
      let tmp = res.data.data.records
      pagingRef.value.complete(tmp);
    }
  })
}

</script>

<style scoped>

</style>